package chapter03.Demo02;


/**
 * 1.时装
 * 2.构造方法
 */
class Student {
    String id;//学生学号
    private String name;//学生姓名
    private int age;//年龄
    private int gender;//性别 0男 1女
    //构造方法
    //多个构造方法（构造方法重载）
    public Student() {
    }

    public Student(String ID){
        id =ID;
    }

    public Student(String id, String name) {
        this.id = id;
        this.name = name;
    }
    //封装一个方法


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
    //封装 有利于对数据校验

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age < 0 || age > 150) {
            System.out.println("输入年龄非法");
        } else {
            this.age = age;
        }
    }
    //封装 有利于发杂功能的重复利用

    public String getGender() {
        if (gender==0){
            return  "男";
        }else {
            return "女";
        }
    }

    public void setGender(String g) {
        if (g.equals("男")) {
            gender = 0;
        } else {
            gender = 1;

        }
    }
}


public class demo2 {
    public static void main(String[] args) {
        Student stu1 = new Student("123456");
    //    stu1.id = "23304010501";
        System.out.println(stu1.id);//查看构造方法设置学号
        //    stu1.name = ""；
        stu1.setName("猪小明");
        System.out.println(stu1.getName());
        stu1.setAge(100000);
        stu1.setGender("女");
        System.out.println(stu1.getGender());
    }
}